const fp = require('lodash/fp')
const cars = require('./code2.data')

// 题干提供的方法
let _average = function (xs) {
  return fp.reduce(fp.add, 0, xs) / xs.length
} //<-无需改动

// fp.prop 是 fp.get 的别名
const averageDollarValue = fp.flowRight(
  _average,
  fp.map(fp.get('dollar_value'))
)

console.log('averageDollarValue的结果是', averageDollarValue(cars))

// 完全使用fp的一种解法
const averageDollarValueX = fp.flowRight(
  fp.mean,
  fp.map(fp.get('dollar_value'))
)

console.log('averageDollarValueX的结果是', averageDollarValueX(cars))
